package cn.yuanqiao.web.controller.archive.appManager;

import cn.yuanqiao.archive.appManager.domain.TenantMdataGroup;
import cn.yuanqiao.archive.appManager.service.ITenantMdataGroupService;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 元数据方案Controller
 * 
 * @author yuanqiao
 * @date 2023-06-06
 */
@RestController
@RequestMapping("/archive/mdataGroup")
public class TenantMdataGroupController extends BaseController
{
    @Autowired
    private ITenantMdataGroupService tenantMdataGroupService;

    /**
     * 查询元数据方案列表
     */
    //@PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:list')")
    @Log(title = "元数据方案", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public AjaxResult list(TenantMdataGroup tenantMdataGroup)
    {
        List<TenantMdataGroup> list = tenantMdataGroupService.selectTenantMdataGroupList(tenantMdataGroup);
        return AjaxResult.success(list);
    }

    /**
     * 复制到下元数据方案列表
     * @param groupId
     * @param type
     * @return
     */
    @Log(title = "复制到下元数据方案列表", businessType = BusinessType.SELECT)
    @GetMapping("/copyGroupList")
    public AjaxResult copyGroupList(@RequestParam Long groupId,@RequestParam Integer type){
        if(StringUtils.isNull(groupId) || StringUtils.isNull(type)){
            return AjaxResult.error("参数错误！");
        }else {
            List<TenantMdataGroup> list = tenantMdataGroupService.copyGroupList(groupId,type);
            return AjaxResult.success(list);
        }
    }

    /**
     * 元数据方案树
     * @param tenantMdataGroup
     * @return
     */
    @Log(title = "元数据方案树", businessType = BusinessType.SELECT)
    @GetMapping("/groupTree")
    public AjaxResult selectGroupTreeList(TenantMdataGroup tenantMdataGroup){
        return success(tenantMdataGroupService.selectGroupTreeList(tenantMdataGroup));
    }
    /**
     * 导出元数据方案列表
     */
    @PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:export')")
    @Log(title = "元数据方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantMdataGroup tenantMdataGroup)
    {
        List<TenantMdataGroup> list = tenantMdataGroupService.selectTenantMdataGroupList(tenantMdataGroup);
        ExcelUtil<TenantMdataGroup> util = new ExcelUtil<TenantMdataGroup>(TenantMdataGroup.class);
        util.exportExcel(response, list, "元数据方案数据");
    }

    /**
     * 获取元数据方案详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:query')")
    @Log(title = "获取元数据方案详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(tenantMdataGroupService.selectTenantMdataGroupByID(ID));
    }

    /**
     * 新增元数据方案
     */
    //@PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:add')")
    @Log(title = "元数据方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TenantMdataGroup tenantMdataGroup)
    {
        return toAjax(tenantMdataGroupService.insertTenantMdataGroup(tenantMdataGroup));
    }

    /**
     * 修改元数据方案
     */
    //@PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:edit')")
    @Log(title = "元数据方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TenantMdataGroup tenantMdataGroup)
    {
        if(StringUtils.isNotNull(tenantMdataGroup.getId())){
            return toAjax(tenantMdataGroupService.updateTenantMdataGroup(tenantMdataGroup));
        }else {
            return  AjaxResult.error("ID不能为空!");
        }

    }

    /**
     * 删除元数据方案
     */
    //@PreAuthorize("@ss.hasPermi('manage:TenantMdataGroup:remove')")
    @Log(title = "元数据方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ID}")
    public AjaxResult remove(@PathVariable Long ID)
    {
        return toAjax(tenantMdataGroupService.deleteTenantMdataGroupByID(ID));
    }
}
